<?php
namespace My\Controller;

use Utuo\BackgroundController;

class ModuleNavigateController extends BackgroundController {
	
	
	public function _initialize() {
		$this->setControllerTitle("一键导航配置");
		$this->setActionTitle(array(
				'index' => '一键导航设置',
		));
	}
	
	// 一键导航设置
	public function indexAction() {
		$m = M("ModuleNavigate");
		$moduleNaigate = $m->find($this->aid);
		if(!$moduleNaigate){
			if(!$m->add(array(
					'id'=>$this->aid,
					'title' => $this->aname,
					'name' => '一键导航'))){
				$this->error("添加导航设置失败");
			}
			$moduleNaigate = $m->find($this->aid);
		}
		$this->assign("moduleNaigate",$moduleNaigate);
		$this->assign("pointJSON",($moduleNaigate['lng'] && $moduleNaigate['lat'])?json_encode(array('lng'=>$moduleNaigate['lng'], 'lat'=>$moduleNaigate['lat'], 'adr'=>$moduleNaigate['address'])):"");
		$this->display();
	}
	
	// 一键导航设置提交
	public function indexPostAction(){
		$d = M("ModuleNavigate");
		if ($d->create()) {
			$d->id = $this->aid;
			if (false !== $d->save()) {
				$this->ajaxSuccess();
			} else {
				$this->ajaxError($d->getError());
			}
		} else {
			$this->ajaxError($d->getError());
		}
	}
	
}